package com.ssii.www.myproject.query;

import com.github.wenhao.jpa.Specifications;
import com.ssii.www.myproject.domain.Task;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.jpa.domain.Specification;

import java.util.Date;

@Data
public class TaskQuery extends BaseQuery {
  //希望通过模糊查询的字段
  private Long state;
  //系统名称
  private String name;
  //申请码
  private String scode;
  //系统版本
  private String version;
  //申请人
  private String applicant;
  //申请日期
  private Date applydate;
  //截止日期
  private Date deadline;
  @Override
  public Specification createSpec() {
    Specification<Task> specification = Specifications.<Task>and().like(StringUtils.isNotBlank(name), "name", "%" + this.name + "%")
      .like(StringUtils.isNotBlank(this.scode), "scode", "%" + this.scode + "%")
      .eq(state!=null,"state",this.state)
      .like(StringUtils.isNotBlank(this.version), "version", "%" + this.version + "%")
      .like(StringUtils.isNotBlank(this.applicant),"applicant","%"+this.applicant+"%")
      .gt(applydate!=null,"applydate",this.version)
      .lt(deadline!=null,"deadline",this.deadline)
        .build();
    return specification;
  }
}
